from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By
from page_locators.loginpage_locator import LoginPageLocator as LL
from Common.base_page import BasePage

class LoginPage(BasePage):

    def __init__(self,driver):
        super().__init__(driver)

    def login(self,username,password,verify='1111'):
        # self.driver.find_element_by_id('username').send_keys(username)
        # self.driver.find_element_by_id('password').send_keys(password)
        # self.driver.find_element_by_id('verify_code').send_keys(verify)
        # self.driver.find_element_by_name('sbtbutton').click()
        # self.driver.find_element(*LL.username_loc).clear()
        # self.driver.find_element(*LL.username_loc).send_keys(username)
        # self.driver.find_element(*LL.password_loc).send_keys(password)
        # self.driver.find_element(*LL.verify_loc).send_keys(verify)
        # self.driver.find_element(*LL.loginbtn).click()
        self.input_text(LL.username_loc,username,"登录页面_登录模块_用户名输入操作")
        self.input_text(LL.password_loc,password,"登录页面_登录模块_密码输入操作")
        self.input_text(LL.verify_loc,verify,"登录页面_登录模块_验证码输入操作")
        self.click_element(LL.loginbtn,"登录页面_登录模块_登录按钮点击操作")

    def get_err_msg_form_login(self):
        """
        获取登录模块异常数据的提示信息
        :return:
        """
        sleep(2)
        # msg = self.driver.find_element(*LL.errmsg_loc).text
        msg = self.get_element_text(LL.errmsg_loc,"登录页面_登录模块_获取登录提示信息操作")
        return msg
